<template>
  <div>
    <el-table v-loading="loading" :data="memberList">
      <el-table-column label="用户ID" align="center" prop="userId"/>
      <el-table-column label="用户名称" align="center" prop="userName"/>
      <el-table-column label="用户在项目中的角色" align="center" prop="role">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_personnel_role" :value="scope.row.role"/>
        </template>
      </el-table-column>
      <el-table-column label="加入时间" align="center" prop="joinedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.joinedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <slot name="operation" :row="scope.row"></slot>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {listMember} from "@/api/project/member";

export default {
  name: "ProjectUser",
  dicts: ['project_personnel_role'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目成员：存储项目与用户的关系表格数据
      memberList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        userId: null,
        userName: null,
        role: null,
        joinedAt: null,
        modifiedAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectId: [
          {required: true, message: "项目ID不能为空", trigger: "blur"}
        ],
        userId: [
          {required: true, message: "用户ID不能为空", trigger: "blur"}
        ],
        role: [
          {required: true, message: "用户在项目中的角色不能为空", trigger: "change"}
        ],
      }
    };
  },
  props: {
    projectId: {
      type: Number
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目成员：存储项目与用户的关系列表 */
    getList() {
      this.loading = true;
      this.queryParams.projectId = this.projectId;
      listMember(this.queryParams).then(response => {
        this.memberList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  }
}
</script>

<style scoped lang="scss">

</style>
